<template>
  <div class="count">
    <h2>当前求和为：{{ countStore.sum }}</h2>
    <h3>欢迎:{{ countStore.title }}，来到：{{ countStore.address }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="add">加</button>
    <button @click="minus">减</button>
  </div>
</template>

<script setup lang="ts" name="Count">
import { ref } from 'vue';
// 引入useCountStore
import { useCountStore } from '@/store/count'
let n = ref(1)
// 使用useCountStore，得到一个专门保存count相关的store
const countStore = useCountStore()
const add = () => {
  // 第一种修改方式
  // countStore.sum += n.value
  // 第二种修改方式
  // countStore.$patch({
  //   sum: 10,
  //   title: '吊毛10',
  //   address: '软件园F区10',
  // })

  // 第三种修改方式
  countStore.increment(n.value)
}
const minus = () => {
  countStore.$patch({
    sum: 0,
    title: '吊毛',
    address: '软件园F区',
  })
}
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 0 10px;
}

select,
button {
  margin: 0 5px;
  height: 25px;
}
</style>